<template>
  <div class="app-container">
    <el-table v-loading="loading" :data="rechargeList">
      <el-table-column label="预存单号" align="center" prop="orderSn" />
      <el-table-column label="预存金额" align="center" prop="account" />
      <el-table-column label="充值方式" align="center" prop="pyName" />
      <el-table-column label="支付状态" align="center">
        <template slot-scope="scope">
          <p>{{ payStatus[scope.row.payStatus] }}</p>
        </template>
      </el-table-column>
      <el-table-column label="是否开票" align="center">

        <template slot-scope="scope">
          <p>{{ invoices[scope.row.translate] }}</p>
        </template>
      </el-table-column>
      <el-table-column label="预存奖励" align="center" prop="rewardType">

        <template slot-scope="scope">
          <p>{{ scope.row.rewardType == 0 ? (scope.row.reward == 100 ? '无' : (scope.row.reward + ' 折')) :
      scope.row.reward }}</p>
        </template>
      </el-table-column>
      <el-table-column label="充值时间" align="center">

        <template slot-scope="scope">
          <p>{{ timestampToDate(scope.row.createTime) }}</p>
        </template>
      </el-table-column>
    </el-table>
    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />
  </div>
</template>

<script>
import { listByuser } from '@/api/finance/recharge'

import { PROPS_ID, WATCH_ID } from '@/constant/const'
import {
  ASSOC_SEARCH_BY_USER,
  PRE_STORED_REWARDS,
  RECHARGE_PARAM,
  RECHARGE_STATUS,
  TRANSLATE_STATUS
} from '@/constant/const'
import { timestampToDate } from '@/utils/time'

export default {
  name: 'preStoredRecords',

  props: {
    ...PROPS_ID
    // dateRange: {
    //   type: Array,
    //   default: null,
    // }
  },

  watch: {
    ...WATCH_ID
  },

  data() {
    return {
      // 遮罩层
      loading: true,
      types: [],
      // 选中数组
      ids: [],

      invoices: TRANSLATE_STATUS,

      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      payStatus: RECHARGE_STATUS,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 充值记录 表格数据
      rechargeList: [],
      dateRange: undefined,
      currentRow: {},
      // 弹出层标题
      title: '',
      // 是否显示弹出层
      open: false,
      paymentVisiable: false,
      rewards: PRE_STORED_REWARDS,
      // 查询参数
      queryParams: { ...ASSOC_SEARCH_BY_USER }
    }
  },
  created() { },

  mounted() {
    this.getList(null)
  },

  methods: {
    timestampToDate,
    /**
     * 查询充值记录 列表
     * @param {Array | null} dateRange
     */
    getList(dateRange) {
      this.loading = true

      if (dateRange) {
        this.queryParams.startTime = dateRange[0] ? new Date(dateRange[0]).getTime() / 1000 : '';
        this.queryParams.endTime = dateRange[1] ? new Date(dateRange[1]).getTime() / 1000 : '';
      }

      listByuser(this.queryParams).then((response) => {
        this.rechargeList = response.rows

        this.total = response.total
        this.loading = false
      })
    },
    // 取消按钮
    cancel() {
      this.open = false
      this.reset()
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        userId: null,
        orderSn: null,
        account: null,
        createTime: null,
        payTime: null,
        payId: null,
        payStatus: null,
        payType: null,
        rewardType: null
      }
      this.resetForm('form')
    },

    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1

      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm')

      this.dateRange = undefined
      this.queryParams = { ...RECHARGE_PARAM }

      this.handleQuery()
    }
  }
}
</script>
